import ACCESS_ENUM from "@/access/accessEnum";
import {
    BankOutlined,
    CrownOutlined,
    HomeOutlined,
    ScheduleOutlined,
    TeamOutlined,
    ThunderboltOutlined
} from "@ant-design/icons";
import { MenuDataItem } from "@ant-design/pro-layout";

// 菜单列表
export const menus = [
    {
        path: "/",
        name: "主页",
        icon: <HomeOutlined />,
    },
    {
        path: "/banks",
        name: "题库",
        icon: <BankOutlined />,
    },
    {
        path: "/brushQuestions/1",
        name: "刷题喵",
        icon: <ThunderboltOutlined />,
    },
    {
        path: "/practise",
        name: "练习喵",
        icon: <ScheduleOutlined />,
        children: [
            {
                path: "/practise/practiseDetails",
                name: "开练喵",
            },
            {
                path: "/practise/practiseQuestions",
                name: "练习题库",
            },
            {
                path: "/practise/practiseAnalytic",
                name: "练习分析",
            },
        ],
    },
    {
        name: "喵圈",
        path: "/mewcircle",
        icon: <TeamOutlined />,
    },
    {
        path: "/admin",
        name: "管理",
        icon: <CrownOutlined />,
        access: ACCESS_ENUM.ADMIN,
        children: [
            {
                path: "/admin/user",
                name: "用户管理",
                access: ACCESS_ENUM.ADMIN,
            },
            {
                path: "/admin/bank",
                name: "题库管理",
                access: ACCESS_ENUM.ADMIN,
            },
            {
                path: "/admin/question",
                name: "题目管理",
                access: ACCESS_ENUM.ADMIN,
            },
        ],
    },
    {
        name: "经典鸡粉",
        path: "https://gfzyl.github.io/blog/",
        target: "_blank",
        icon: <CrownOutlined />,
    },
] as MenuDataItem[];

/**
 * 根据全部路径查找菜单
 * @param path
 */
export const findAllMenuItemByPath = (path: string): MenuDataItem | null => {
    return findMenuItemByPath(menus, path);
};

//
/**
 * 递归根据路径查找菜单
 * @param menus
 * @param path
 */
export const findMenuItemByPath = (
    menus: MenuDataItem[],
    path: string
): MenuDataItem | null => {
    for (const menu of menus) {
        if (menu.path === path) {
            return menu;
        }
        if (menu.children) {
            const matchedMenuItem = findMenuItemByPath(menu.children, path);
            if (matchedMenuItem) {
                return matchedMenuItem;
            }
        }
    }
    return null;
};
